$(function  () {
    $.post(
        ipurl+'/menu/get',
        function(result) {
            if(result.code == 200){
                var menulist = result.data.results;
                var menuhtml = '<option value="0"></option>';
                for(var i=0;i<menulist.length;i++){
                    menuhtml+='<option value="'+menulist[i].ID+'">';
                    menuhtml+=menulist[i].name;
                    menuhtml+='</option>';
                }
                $("#parent").html(menuhtml);
            }
        }
    );

    //cookie数据赋值
    var id = $.cookie("mid");
    var name = $.cookie("mname");
    var address = $.cookie("mmaddress");
    var parent = $.cookie("mparentID");
    $("#name").val(name);
    $("#maddress").val(address);
    $("#parent").val(parent);

    layui.use('form', function(){
        var form = layui.form();
        //监听提交
        form.on('submit(edit)', function(data){
              var name1 = $("#name").val();
              var maddress1 = $("#maddress").val();
              var parentID = $("#parent").val();


              $.ajax({
                url: ipurl+'/menu/update',
                data: {
                    ID:id,
                    name: name1,
                    maddress: maddress1,
                    parentID: parentID
                },
                type: "POST",
                //dataType: "json",
                complete: function(data) {
                }
            });
            x_admin_close();
            top.location.reload();
                 });
    });

})
